package cn.edu.scau.service.impl;

import cn.edu.scau.dao.RecoveryRegisterMapper;
import cn.edu.scau.entity.RecoveryRegister;
import cn.edu.scau.service.RecoveryRegisterService;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RecoveryRegisterServiceImpl implements RecoveryRegisterService {
    @Autowired
    RecoveryRegisterMapper recoveryRegisterMapper;

    //@Transactional(isolation = Isolation.READ_COMMITTED,propagation = Propagation.REQUIRED,rollbackFor = RuntimeException.class)

    @Override
    public boolean insert(RecoveryRegister recoveryRegister) {
        int line = recoveryRegisterMapper.insertSelective(recoveryRegister);
        if(1==line)
        {
            return true;
        }
        return false;
    }

    @Override
    public boolean update(RecoveryRegister recoveryRegister) {
        int line = recoveryRegisterMapper.updateByPrimaryKeySelective(recoveryRegister);
        return line ==1? true:false;
    }

    @Override
    public boolean delete(Integer recoveryRegisterID) {
        int line = recoveryRegisterMapper.deleteByPrimaryKey(recoveryRegisterID);
        return line ==1? true:false;
    }

    @Override
    public boolean batchdelete(Integer[] recoveryRegisterIDs) {
        return false;
    }

    @Override
    public RecoveryRegister selectByPrimaryKey(Integer recoveryRegisterID) {
        return recoveryRegisterMapper.selectByPrimaryKey(recoveryRegisterID);
    }

    @Override
    public List<RecoveryRegister> selectByNurseID(Integer nurseID) {
        return recoveryRegisterMapper.selectByNurseID(nurseID);
    }

    @Override
    public List<RecoveryRegister> selectAll() {
        return recoveryRegisterMapper.selectAll();
    }

    @Override
    public List<RecoveryRegister> find(Integer recoveryRegisterID, Integer nurseID, String nurseName, Integer customerID, String customerName) {
    	if(recoveryRegisterID!=null&&recoveryRegisterID<1){
    		recoveryRegisterID=null;
        }
    	if(nurseID!=null&&nurseID<1){
    		nurseID=null;
        }
        if(StringUtils.isBlank(nurseName)){
        	nurseName=null;
        }
        if(recoveryRegisterID!=null&&recoveryRegisterID<1){
    		recoveryRegisterID=null;
        }
        if(StringUtils.isBlank(customerName)){
        	customerName=null;
        }
    	return recoveryRegisterMapper.find(recoveryRegisterID, nurseID, nurseName, customerID, customerName);
    }

	@Override
	public List<RecoveryRegister> findWithNurseID(Integer recoveryRegisterID, Integer nurseID, Integer customerID, String customerName) {
		if(recoveryRegisterID!=null&&recoveryRegisterID<1){
    		recoveryRegisterID=null;
        }
    	if(nurseID!=null&&nurseID<1){
    		System.out.println("带护士编号查找护士编号为空或小于1");
    		return null;
        }
        if(recoveryRegisterID!=null&&recoveryRegisterID<1){
    		recoveryRegisterID=null;
        }
        if(StringUtils.isBlank(customerName)){
        	customerName=null;
        }
        return recoveryRegisterMapper.findWithNurseID(recoveryRegisterID, nurseID, customerID, customerName);
	}
}
